package personal.vivian.impl;

import javax.annotation.PostConstruct;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import personal.vivian.SelfCallService;

@Service
public class SelfCallServiceImpl implements SelfCallService {
     @Autowired
      private ApplicationContext applicationContext;
    @Autowired
    private SelfCallService selfCallService;
    @PostConstruct
    public void setSelfCallService(){
       // ApplicationContext applicationContext= new ClassPathXmlApplicationContext("beans.xml");
       // selfCallService = applicationContext.getBean(this.getClass());
    }
    /**
     * 方法A
     */
    public void selfCallA() {

        System.out.println("我是方法A");
        System.out.println("是否是AOP拦截:" + AopUtils.isAopProxy(this));
        this.selfCallB();
        //((SelfCallService)AopContext.currentProxy()).selfCallB();
        //self是代理 this不是
        //selfCallService.selfCallB();
    }

    /**
     * 方法B
     */
    public void selfCallB() {
        System.out.println("我是方法B");
    }

   /* @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext= applicationContext;
    }*/
}
